using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Integrator.Common;
using Integrator.DAL;

namespace Integrator
{
    public partial class FormDBF : Form
    {
        private DataTable data = null;
        public FormDBF()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "dBASE files (*.dbf)|*.dbf";
            ofd.ShowDialog();

            if (ofd.FileName.Length > 0)
            {
                data = DBFHelper.ReadDBF(ofd.FileName);
                dataGridView1.DataSource = data;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (data != null)
                {
                    this.Cursor = Cursors.WaitCursor;
                    new SqlHelper().BulkInsertData(data);
                    MessageBox.Show("done");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
    }
}